package org.spiderflow.config;

/**
 * 应用系统级别的错误码
 *
 * Created by bysocket on 14/03/2017.
 */
public enum GlobalErrorInfoEnum implements ErrorInfoInterface{
    //regain
    // 全局系统异常 占用范围-999 -- 1000

    //全局系统级别异常
    SUCCESS("1", "success"),
    FAIL("2", "fail"),
    SYSTEM_ERROR("-100","系统异常") ,
	TOKEN_ERROR_NULL("-101","登录信息不存在"),
    PARAM_ERROR("-102","参数异常") ,
    USER_NO_LOGIN("-103","您还未登录！") ,
    NETWORK_BUSY("-104","网络繁忙，请稍后再试！") ,
    USER_NO_KEY("-105","您还未登录！") ,

    //业务级别异常
    PAY_NO_USER("201","支付成功！") ,
    ;

    private String code;

    private String message;

    GlobalErrorInfoEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public void setMessage(String ... msgs){
        for(String msg:msgs){
            this.message=this.message.replaceFirst("#",msg);
        }
    }

    public String getCode(){
        return this.code;
    }

    public String getMessage(){
        return this.message;
    }
    
    public static GlobalErrorInfoEnum getResponseMsg(String code){
        for(GlobalErrorInfoEnum responseInfo:GlobalErrorInfoEnum.values()){
            if(code.equals(responseInfo.getCode())){
                return responseInfo;
            }
        }
        return SYSTEM_ERROR;
    }
}
